#include "wopTextureManager.h"
#include "wopTexture2D.h"
#include "wopImageInterface.h"

wopTextureManager* wopTextureManager::mTextureManager = NULL;
std::vector<wopTexture2D*> wopTextureManager::mTextures;

wopTextureManager* wopTextureManager::getTextureManager()
{
	if (mTextureManager == NULL)
	{
		mTextureManager = new wopTextureManager();
	}
	return mTextureManager;
}

void wopTextureManager::killTextureManager()
{
	std::vector<wopTexture2D*>::iterator _iter;
	for (_iter = mTextures.begin(); _iter != mTextures.end(); ++_iter)
	{
		delete *_iter;
		*_iter = NULL;
	}

	mTextures.clear();

	delete mTextureManager;
	mTextureManager = NULL;
}

wopTexture2D* wopTextureManager::createTexture2D(const wopImageInterface& image)
{
	wopTexture2D* _texture = new wopTexture2D();
	_texture->upload(image.width(), image.height(), (char*)image.bits(), GL_RGBA, GL_BGRA);

	mTextures.push_back(_texture);

	return _texture;
}